package com.se.mapper;

import com.se.domain.mysql.UserDO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select count(*) from user where user_id = #{userId} and active = true")
    boolean existByUserId(@Param("userId") Long userId);

    @Select("select * from user where openid = #{openId} and active = true")
    UserDO getByOpenId(@Param("openId") String openId);
    @Insert("insert into user(openid, uname) " +
            "values (#{openid}, #{uname}) " +
            "on duplicate key update active = true")
    @Options(useGeneratedKeys = true, keyProperty = "userId", keyColumn = "user_id")
    void insertUser(UserDO userDO);

    @Select("select user_id from user where openid = #{openid} and active = true")
    Long getUserIdByOpenId(@Param("openid") String openid);

    @Update("update user set uname = #{uname}, img_url = #{imgUrl} where user_id = #{userId}")
    void updateUserInfo(@Param("userId") Long userId, @Param("uname") String uname, @Param("imgUrl") String imgUrl);

    @Select("select * from user where user_id = #{userId} and active = true")
    UserDO getByUserId(@Param("userId") Long userId);

    List<UserDO> listByUserIds(@Param("list") List<Long> userIds);

    List<String> listOpenIdByUserIds(@Param("list") List<Long> userIds);
}
